using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using Entities;
using Utility;

namespace BUS
{
    public class tbTrangthaisanphamBUS
    {
        public static void Insert(tbTrangthaisanpham ttsp)
        {
            tbTrangthaisanphamDAL ttspDAL = new tbTrangthaisanphamDAL();
            ttspDAL.Insert(ttsp);
        }
        public static void Update(tbTrangthaisanpham ttsp)
        {
            tbTrangthaisanphamDAL ttspDAL = new tbTrangthaisanphamDAL();
            ttspDAL.Update(ttsp);
        }
        public static void Delete(int iD)
        {
            tbTrangthaisanphamDAL ttspDAL = new tbTrangthaisanphamDAL();
            ttspDAL.Delete(iD);
        }
        public static tbTrangthaiCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            tbTrangthaisanphamDAL ttspDAL = new tbTrangthaisanphamDAL();
            return ttspDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbTrangthaiCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbTrangthaisanphamDAL ttspDAL = new tbTrangthaisanphamDAL();
            return ttspDAL.Get(cri.Criter, 0, 0, tbTrangthaispColumn.Mattsp.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static tbTrangthaisanpham GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbTrangthaispColumn.Mattsp.ToString(), Condition.EQUAL, iD);
            tbTrangthaisanphamDAL ttspDAL = new tbTrangthaisanphamDAL();
            tbTrangthaiCollection tbtrangthaiCollection = ttspDAL.Get(cri.Criter, 0, 0, tbTrangthaispColumn.Mattsp.ToString(), OrderDirection.ASC.ToString(), out total);
            if (tbtrangthaiCollection.Count > 0)
                return tbtrangthaiCollection[0];
            return null;
        }
        public static tbTrangthaiCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbTrangthaisanphamDAL ttspDAL = new tbTrangthaisanphamDAL();
            return ttspDAL.Get(cri.Criter, 1, number,
             tbTrangthaispColumn.Mattsp.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbTrangthaiCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbTrangthaisanphamDAL ttspDAL = new tbTrangthaisanphamDAL();
            return ttspDAL.Get(cri.Criter, 1, number,
               tbTrangthaispColumn.Mattsp.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
}
